home *** CD-ROM | disk | FTP | other *** search
/ Die Ultimative Software-P…i Collection 1996 & 1997 / Die Ultimative Software-Pakete CD-ROM fur Atari Collection 1996 & 1997.iso / g / gnu_c / crssrc16.zoo / doc / intro.4 < prev    next >
Encoding:
Text File  |  1989-07-22  |  5.4 KB  |  224 lines

  1. .\" Copyright 1980 Kenneth C. R. C. Arnold and The Regents of the
  2. .\" University of California.  Permission is granted to freely
  3. .\" distribute curses and its documentation provided that this
  4. .\" notice is left intact.
  5. .\"
  6. .\"    @(#)intro.4    6.1 (Berkeley) 4/23/86
  7. .\"
  8. .sh 1 "Cursor Motion Optimization: Standing Alone"
  9. .pp
  10. It is possible to use the cursor optimization functions of this screen package
  11. without the overhead and additional size of the screen updating functions.
  12. The screen updating functions are designed for uses
  13. where parts of the screen are changed,
  14. but the overall image remains the same.
  15. This includes such programs as
  16. .b rogue
  17. and
  18. .b vi \**.
  19. .(f
  20. \**
  21. .b rogue
  22. actually uses these functions,
  23. .b vi
  24. does not.
  25. .)f
  26. Certain other programs
  27. will find it difficult to use these functions in this manner
  28. without considerable unnecessary program overhead.
  29. For such applications,
  30. such as some
  31. .q "\fIcrt hacks\fR\|" \**
  32. .(f
  33. \**
  34. Graphics programs designed to run on character-oriented terminals.
  35. I could name many,
  36. but they come and go,
  37. so the list would be quickly out of date.
  38. Recently, there have been programs such as
  39. .b rain ,
  40. .b rocket ,
  41. and
  42. .b gun .
  43. .)f
  44. and optimizing
  45. .b more (1)-type
  46. programs,
  47. all that is needed is the motion optimizations.
  48. This, therefore, is a description
  49. of what some of what goes on at the lower levels of this screen package.
  50. The descriptions assume a certain amount of familiarity
  51. with programming problems and some finer points of C.
  52. None of it is terribly difficult,
  53. but you should be forewarned.
  54. .sh 2 "Terminal Information"
  55. .pp
  56. In order to use a terminal's
  57. features to the best of a program's abilities,
  58. it must first know what they are\**.
  59. .(f
  60. \**
  61. If this comes as any surprise to you,
  62. there's this tower in Paris they're thinking of junking
  63. that I can let you have for a song.
  64. .)f
  65. The \*(tc \*(db describes these,
  66. but a certain amount of decoding is necessary,
  67. and there are, of course,
  68. both efficient and inefficient ways of reading them in.
  69. The algorithm that the uses is taken from
  70. .b vi
  71. and is hideously efficient.
  72. It reads them
  73. in a tight loop
  74. into a set of variables
  75. whose names are two uppercase letters with some mnemonic value.
  76. For example,
  77. .Vn HO
  78. is a string which moves the cursor to the "home" position\**.
  79. .(f
  80. \**
  81. These names are identical to those variables
  82. used in the
  83. .b termcap (5)
  84. \*(db to describe each capability.
  85. See Appendix A for a complete list of those read,
  86. and the
  87. .b termcap (5)
  88. manual page
  89. for a full description.
  90. .)f
  91. As there are two types of variables involving ttys,
  92. there are two routines.
  93. The first,
  94. .Fn gettmode ,
  95. sets some variables based upon the tty modes accessed by
  96. .b gtty (2)
  97. and
  98. .b stty (2) .
  99. The second,
  100. .Fn setterm ,
  101. a larger task by reading in the descriptions from the \*(tc \*(db.
  102. This is the way these routines are used by
  103. .Fn initscr :
  104. .(b
  105. .(l I
  106. \*fif\fP (isatty(0)) {
  107.        gettmode();
  108.        \*fif\fP ((sp=getenv("TERM")) != NULL)
  109.                setterm(sp);
  110.     \*felse\fP
  111.            setterm(Def\*_term);
  112. }
  113. \*felse\fP
  114.        setterm(Def\*_term);
  115. \*_puts(TI);
  116. \*_puts(VS);
  117. .)l
  118. .)b
  119. .pp
  120. .Fn isatty
  121. checks to see if file descriptor 0 is a terminal\**.
  122. .(f
  123. \**
  124. .Fn isatty
  125. is defined in the default C library function routines.
  126. It does a
  127. .b gtty (2)
  128. on the descriptor and checks the return value.
  129. .)f
  130. If it is,
  131. .Fn gettmode
  132. sets the terminal description modes from a
  133. .b gtty (2) .
  134. .Fn getenv
  135. is then called to get the name of the terminal,
  136. and that value (if there is one) is passed to
  137. .Fn setterm ,
  138. which reads in the variables from \*(tc
  139. associated with that terminal.
  140. .Fn getenv "" (
  141. returns a pointer to a string containing the name of the terminal,
  142. which we save in the character pointer
  143. .Vn sp .)
  144. If
  145. .Fn isatty
  146. returns false,
  147. the default terminal
  148. .Vn Def\*_term
  149. is used.
  150. The
  151. .Vn TI
  152. and
  153. .Vn VS
  154. sequences initialize the terminal
  155. .Fn \*_puts "" (
  156. is a macro which uses
  157. .Fn tputs
  158. (see
  159. .b termcap (3))
  160. and 
  161. .Fn \*_putchar ""
  162. to put out a string).
  163. .Fn endwin
  164. undoes these things.
  165. .sh 2 "Movement Optimizations, or, Getting Over Yonder"
  166. .pp
  167. Now that we have all this useful information,
  168. it would be nice to do something with it\**.
  169. .(f
  170. \**
  171. Actually,
  172. it
  173. .i can
  174. be emotionally fulfilling just to get the information.
  175. This is usually only true, however,
  176. if you have the social life of a kumquat.
  177. .)f
  178. The most difficult thing to do properly is motion optimization.
  179. When you consider how many different features various terminals have
  180. (tabs, backtabs, non-destructive space, home sequences, absolute tabs, .....)
  181. you can see that deciding how to get from here to there
  182. can be a decidedly non-trivial task.
  183. The editor
  184. .b vi
  185. uses many of these features,
  186. and the routines it uses to do this take up many pages of code.
  187. Fortunately, I was able to liberate them with the author's permission,
  188. and use them here.
  189. .pp
  190. After using
  191. .Fn gettmode
  192. and
  193. .Fn setterm
  194. to get the terminal descriptions,
  195. the function
  196. .Fn mvcur
  197. deals with this task.
  198. It usage is simple:
  199. you simply tell it where you are now and where you want to go.
  200. For example
  201. .(l
  202. mvcur(0\*,0\*,LINES/2\*,COLS/2)
  203. .)l
  204. .lp
  205. would move the cursor from the home position (0\*,0)
  206. to the middle of the screen.
  207. If you wish to force absolute addressing,
  208. you can use the function
  209. .Fn tgoto
  210. from the
  211. .b termlib (7)
  212. routines,
  213. or you can tell
  214. .Fn mvcur
  215. that you are impossibly far away,
  216. like Cleveland.
  217. For example,
  218. to absolutely address the lower left hand corner of the screen
  219. from anywhere
  220. just claim that you are in the upper right hand corner:
  221. .(l
  222. mvcur(0\*,COLS\-1\*,LINES\-1\*,0)
  223. .)l
  224.